<?php
require_once 'util/class.daofactory.php';

class NotifyService {
	
	public function addNotify($userId, $values) {
		$result = array();
		if($userId==null || !is_int($userId) || $userId<=0
			|| $values==null || count($values)==0) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		global $notifyDao;
		if($notifyDao==null) {
			$result['status']=Constants::$ERROR_DB;
			return $result;
		}
		
		$success = $notifyDao->addNotify($userId, $values);
		$result['status']=Constants::$SUCCESS;
		$result['data']=$success;
		return $result;
	}
	
	public function removeNotify($userId, $values) {
		$result = array();
		if($userId==null || !is_int($userId) || $userId<=0
				|| $values==null || count($values)==0) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		global $notifyDao;
		if($notifyDao==null) {
			$result['status']=Constants::$ERROR_DB;
			return $result;
		}
		
		$success = $notifyDao->removeNotify($userId, $values);
		$result['status']=Constants::$SUCCESS;
		$result['data']=$success;
		return $result;
	}
	
	public function getNotify($userId) {
		$result = array();
		if($userId==null || !is_int($userId) || $userId<=0) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		global $notifyDao;
		if($notifyDao==null) {
			$result['status']=Constants::$ERROR_DB;
			return $result;
		}
		
		$notify = $notifyDao->getNotify($userId);
		$result['status']=Constants::$SUCCESS;
		$result['data']=($notify==null?array():$notify);
		return $result;
	}
}

